/*
 * Group 3, User Interface Programming II (vt11)
 * Pooya | Flora | Monica | Can
 */
package vical.view;

import vical.view.tutorial.TutorialContainer;
import java.awt.Component;
import vical.view.tutorial.GlassTutorial;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import vical.model.Internationalization;
import vical.utility.ShortcutManager;
import vical.utility.TransparencyManager;

/**
 * The main window, responsible to layout other panels properly.
 * 
 * @author Can
 */
public class MainWindow extends SmartFrame implements TutorialContainer{

    /**
     * Components:
     * the main window contains of topPanel and centerPanel
     * the centerPanel contains of leftPanel and viewPanel
     */
    private TopPanel topPanel;
    private JPanel centerPanel;
    private LeftPanel leftPanel;
    private ViewPanel viewPanel;
    private MenuBar menuBar;

    public MainWindow() {
        initComponents();
        
        ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {

            public void handle() {
                showTutorial(false);
            }
        }, KeyEvent.VK_ESCAPE);
    }

    private void initComponents() {

        topPanel = new TopPanel(this);
        centerPanel = new JPanel(new BorderLayout());
        // !!the viewPanel must be in front of leftPanel!!
        viewPanel = new ViewPanel(this);
        leftPanel = new LeftPanel(this);
        menuBar = new MenuBar(this);

        centerPanel.add(BorderLayout.NORTH, topPanel);
        centerPanel.add(BorderLayout.WEST, leftPanel);
        centerPanel.add(BorderLayout.CENTER, viewPanel);

        this.setTitle(Internationalization.getString("calendar_title"));

        this.getContentPane().setLayout(new BorderLayout());
        this.setJMenuBar(menuBar);
        this.getContentPane().add(BorderLayout.CENTER, centerPanel);

        this.setMinimumSize(new Dimension(600, 400));
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public void setOpacity(float opaValue) {
        TransparencyManager.setOpacity(opaValue, this);
    }

    public void updateLeftPanel() {
        leftPanel.refresh();
    }

    @Override
    protected Dimension getDefaultSize() {
        return new Dimension(800, 500);
    }

    @Override
    protected Point getDefaultLocation() {
        return new Point(100, 100);
    }

    public Component getAddEntryButton() {
        return topPanel.getAddEntryButton();
    }

    public Component getNavigationBar() {
        return viewPanel.getNavigationBar();
    }

    public ViewPanel getViewPanel() {
        return viewPanel;
    }

    public Component getLeftPanel() {
        return leftPanel;
    }

    public Component getMiniCalendar() {
        return this.leftPanel.getMiniCal();
    }

    public Component getTopPanel() {
        return topPanel;
    }

    public Component getTransparencyChanger() {
        return topPanel.getTransparencyChanger();
    }

    public void setGlassTutorial(GlassTutorial glassTutorial) {
        this.getGlassPane().setVisible(false);
        this.setGlassPane(glassTutorial);
        this.getGlassPane().setVisible(true);
    }

    public void showTutorial(boolean bShow) {
        this.getGlassPane().setVisible(bShow);
    }
}
